import { RecommentdAction } from "../action/recommentdAction";
import {
  Constant
} from "../constan";
interface Props {
  productList: Array<any>;
  error: string | null;
  loading: boolean
}

const initState: Props = {
  error: null,
  productList: [],
  loading: true,
};

export const recommentdProducts = (
  prevState = initState,
  action: RecommentdAction
) => {
  switch (action.type) {
    case Constant.FETCH_RECOMMEND_PRODUCIS_START:
      const res = { ...prevState, loading: true };
      return res;
    case Constant.FETCH_RECOMMEND_PRODUCIS_SUCCESS:
      return { ...prevState, loading: false, productList: action.payload, error: null };
    case Constant.FETCH_RECOMMEND_PRODUCIS_FAIL:
      return { ...prevState, loading: false, error: action.payload };
    default:
      return prevState;
  }
};
